﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RedirectPage();
        //test_String_Split();
        //test_DateTime_WeekNumber();
        //Redirect301();
        //Nullable();
        //List();
    }

    private void RedirectPage()
    {
        //Response.Redirect("GoogleMap/Default.aspx");  //  RedirectGoolgeMap
        //Response.Redirect("Dotnet3/Extension Methods/Default.aspx");  //  Extension Methods
        //Response.Redirect("Linq/Default.aspx");  //  Linq
        Response.Redirect("List/Default.aspx");  //  List<T>

        //Server.Transfer("Delegate/Default.aspx");  //  List<T>
        //Server.Transfer("Others/Default.aspx");  //  Others
        //Server.Transfer("Linq/MyLinq/Default.aspx");  //  Linq
        //Server.Transfer("Resource/Default.aspx");  //  Resource

        //Response.Redirect("DatePicker/Default.aspx");  //  DatePicker
        Response.Redirect("AspNet_PageControls/Grid/Default.aspx");  //  Grid
    }
    private void test_String_Split()
    {
        string str1 = "Vital Stats_N";
        string[] strArray = new string[2];
        strArray = str1.Split('_');

        Label1.Text = strArray[0];
        Label2.Text = strArray[1];
    }
    private void test_DateTime_WeekNumber()
    {
        //Label1.Text = dt.ToString("yyyyMMdd");
        DateTime dt = DateTime.Now;
        Label1.Text = DatePart(dt).ToString();
        Label2.Text = "";
    }
    private int DatePart(System.DateTime dt)
    {
        int weeknow = Convert.ToInt32(dt.DayOfWeek);//今天星期几
        int daydiff = (-1) * (weeknow + 1);//今日与上周末的天数差
        int days = System.DateTime.Now.AddDays(daydiff).DayOfYear;//上周末是本年第几天
        int weeks = days / 7;
        if (days % 7 != 0)
        {
            weeks++;
        }
        //此时，weeks为上周是本年的第几周
        return (weeks + 1);
    }
    private void Redirect301()
    { 
        Response.Status = "301 Moved Permanently";
        Response.AddHeader("Location","http://farlee.info");
    }
    private void Nullable()
    {
        int? x = null; int y = x ?? -10;
        Label1.Text = x.ToString();
        Label2.Text = y.ToString();
    }
    private void List()
    {
        List<int> list1 = new List<int>();
        List<string> list2 = new List<string>();
        list1.Add(2);
        list2.Add("It is snowing in the mountains.");
        Label1.Text = list1.ElementAt<int>(0).ToString();
        Label2.Text = list2.ElementAt<string>(0);
    }
}
